﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dawn_of_Man;
using System.IO;
using System.Diagnostics;

namespace DOMTextClient
{
    public class Controller
    {
        public Tribe generateTribe()
        {
            Tribe t = new Tribe();
            t.tribe = new List<TribesMan>();
            List<String> tribesmanNames = GenerateNames();
            Chieftain chief = new Chieftain();
            chief.name = RandomName(tribesmanNames);
            t.chief = chief;
            Random random = new Random();
            for (int i = 0; i < 10; i++)
            {
                TribesMan man = new TribesMan();
                man.name = RandomName(tribesmanNames);
                man.age = random.Next(16, 25);
                man.health = 100;
                man.hunger = 100;
                if (i % 2 == 0)
                    man.sex = true;
                else
                    man.sex = false;
                t.tribe.Add(man);
            }
            Village v = new Village();
            v.name = "Ugh!";
            t.village = v;
            return t;
        }
        private List<String> GenerateNames()
        {
            List<String> tribesmanNames = new List<String>();
            try 
            {
                // Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader(@"C:\Arbejde\Dawn of Man\DOMTextClient\names.txt")) 
                {
                    String line;
                    // Read and display lines from the file until the end of 
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null) 
                    {
                        tribesmanNames.Add(line);
                    }
                }
            }
            catch (Exception e) 
            {
                // Let the user know what went wrong.
                Debug.WriteLine("Could not read: " + e.Message);
            }
            return tribesmanNames;
        }

        private String RandomName(List<String> tribesmanNames)
        {
            String name = null;
            Random random = new Random();
            int iName1 = random.Next(0, tribesmanNames.Count);
            int iName2 = random.Next(0, tribesmanNames.Count);
            String name1 = tribesmanNames.ElementAt<String>(iName1);
            String name2 = tribesmanNames.ElementAt<String>(iName2);
            name2 = name2.ToLower();
            name = name1 + name2;

            return name;
        }
    }
}
